package com.triangle_diamond_exercises;

public class TriangleDiamondExercises {
    public static void main(String[] args)
    {
        System.out.println("Easiest exercise ever");
        asterisk();
        newline();
        System.out.println("Draw a horizontal line");
        horizontal_line(8);
        System.out.println("Draw a vertical line");
        vertical_line(3);
        System.out.println("Draw a right triangle");
        right_triangle(3);
        System.out.println("Isosceles triangle");
        isosceles_triangle(3);
        System.out.println("Diamond");
        diamond(3);
        System.out.println("Diamond with Name");
        diamond_w_name(3, "DanPark");

    }

    public static void asterisk()
    {
        System.out.print("*");
    }

    public static void newline()
    {
        System.out.println();
    }

    public static void horizontal_line(int n)
    {
        for (int x = 0; x < n; x++) {
            asterisk();
        }
        newline();
    }

    public static void vertical_line(int n)
    {
        for (int x = 0; x < n; x++) {
            asterisk();
            newline();
        }
    }

    public static void right_triangle(int n)
    {
        for (int x = 1; x <= n; x++) {
            horizontal_line(x);
        }
    }

    public static void isosceles_triangle(int n)
    {
        for (int x = 1; x <= n; x++) {
            centered_line(x, n);
        }
    }

    public static void upper_diamond_half(int n)
    {
        for (int x = 1; x < n; x++) {
            centered_line(x, n);
        }
    }

    public static void bottom_diamond_half(int n)
    {
        for (int x = n-1; x>=1; x--){
            centered_line(x, n);
        }
    }

    public static void blank_space(int l, int n)
    {
        for (int x = 0; x < n-l; x++) {
            System.out.print(" ");
        }
    }

    public static void centered_line(int x, int n)
    {
        blank_space(x, n);
        horizontal_line(x*2-1);
    }

    public static void diamond(int n)
    {
        upper_diamond_half(n);
        horizontal_line(n*2-1);
        bottom_diamond_half(n);
    }

    public static void diamond_w_name(int n, String name)
    {
        upper_diamond_half(n);
        System.out.println(name);
        bottom_diamond_half(n);
    }
}
